import { keysOf } from "element-plus/es/utils/objects.mjs";
import { Random } from "mockjs";

/** 生成一个Token值 */
export function generateToken() {
    return `token-${Random.integer(1000, 9999)}-${Random.integer(1000, 9999)}-${Random.integer(1000, 9999)}-${Random.integer(1000, 9999)}`
}

type MatchValueFn<T> = (value: T) => boolean
/** 查询Map数据根据值查询Key */
export function findMapKeyByValue<T, K>(map: Map<T, K>, value: K | MatchValueFn<K>) {
    let fn: MatchValueFn<K> = value as MatchValueFn<K>
    if (typeof value !== 'function') {
        fn = (val: K) => val === value
    }
    for (let [key, val] of map) {
        if (fn(val)) {
            return key;
        }
    }
    return undefined;
}